Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@zhennann/trim-html

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zhennann/trim-html

trim html...

  • 0.1.12
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

trim-html

Cutting a HTML String without breaking HTML Tags

Build Status

Installation

Node.js

npm package

    npm install trim-html

use in node.js

    var trimHtml = require('trim-html');

Usage

node.js

    var trimmed = trimHtml(html);

Options

limit

Char limit (default 100)

wordBreak

Break text on half of word (default false)

preserveTags

Maintain HTML tags (default true)

suffix

string that will be appended at the end

link to full content

example:

var html = `<div><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, 
            sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </p><p>Ut 
            enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip 
            ex ea commodo consequat. </p><p>Duis aute irure dolor in reprehenderit in 
            voluptate velit esse cillum dolore eu fugiat nulla pariatur. </p><p>Excepteur 
            sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit 
            anim id est laborum.</p></div>`;
var trim = trimHtml(html, { limit: 200 });
// returns object
{
   html: `<div><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit,
   sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </p><p>Ut
   enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut...
   </p></div>`,
   more: true // indicates if limit is reached
}

Keywords

FAQs

Package last updated on 27 Mar 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc